Skip to content

[KVCache] Support environment variable overrides for AttentionStore c…#7455

Open
jackyYang6 wants to merge 1 commit intoPaddlePaddle:developfrom
jackyYang6:kvcache/as-config
Open

[KVCache] Support environment variable overrides for AttentionStore c…#7455
jackyYang6 wants to merge 1 commit intoPaddlePaddle:developfrom
jackyYang6:kvcache/as-config

Conversation

@jackyYang6
Copy link
Copy Markdown
Contributor

@jackyYang6 jackyYang6 commented Apr 17, 2026

Motivation

AttentionStore's namespace, pod_name, and model_version are currently only configurable via constructor arguments. In K8s deployments, these values are typically derived from Pod environment variables (e.g., AS_NAMESPACE, AS_POD_NAME, AS_MODEL_VERSION). Without environment variable overrides, deployment configuration is inflexible.

Modifications

Modified file: fastdeploy/cache_manager/transfer_factory/mooncake_store/attention_store.py

Added environment variable overrides for AttentionStoreConfig fields before SDK initialization in AttentionStore.__init__:

self.config.namespace = os.getenv("AS_NAMESPACE", self.config.namespace)
self.config.pod_name = os.getenv("AS_POD_NAME", self.config.pod_name)
self.config.model_version = os.getenv("AS_MODEL_VERSION", self.config.model_version)
  • When environment variables are not set, the original constructor defaults are preserved (no behavior change).
  • Environment variables take precedence over constructor arguments when set.

Usage or Command

Set the corresponding environment variables before launching the service:

export AS_NAMESPACE=my-model
export AS_POD_NAME=my-pod-0
export AS_MODEL_VERSION=v1

Accuracy Tests

Not applicable — this change does not affect model outputs.

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 17, 2026

Thanks for your contribution!

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@e952720). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...transfer_factory/mooncake_store/attention_store.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7455   +/-   ##
==========================================
  Coverage           ?   73.47%           
==========================================
  Files              ?      398           
  Lines              ?    54979           
  Branches           ?     8613           
==========================================
  Hits               ?    40398           
  Misses             ?    11873           
  Partials           ?     2708           
Flag Coverage Δ
GPU 73.47% <25.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


try:
self.config.namespace = os.getenv("MODEL_ID", self.config.namespace)
self.config.pod_name = os.getenv("FD_POD_NAME", self.config.pod_name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个Pod Name 需要和上报给IC 和 IM 的pod name 对齐吗?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已确认不依赖此作为索引

hong19860320
hong19860320 previously approved these changes Apr 17, 2026
Copy link
Copy Markdown
Collaborator

@hong19860320 hong19860320 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

PaddlePaddle-bot

This comment was marked as outdated.

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-20 18:01:43

📋 Review 摘要

PR 概述:为 AttentionStore 的 namespacepod_namemodel_version 新增环境变量覆盖能力,并根据 ENABLE_EP_DP_IN_FD 拼接 splitwise_roledp_idpod_name
变更范围cache_manager/ — AttentionStore 配置初始化
影响面 TagKVCache

📝 PR 规范检查

PR 描述中的代码示例与实际 diff 不一致:描述仅展示了 AS_NAMESPACEAS_POD_NAMEAS_MODEL_VERSION 三个环境变量覆盖,但实际代码还新增了 ENABLE_EP_DP_IN_FD 控制的 pod_name 拼接逻辑以及 splitwise_role 字段,建议同步更新 PR 描述。

问题

级别 文件 概述
🔴 Bug attention_store.py:70 int(os.getenv("ENABLE_EP_DP_IN_FD", ...)) 对非数字字符串会抛 ValueError,导致初始化失败

总体评价

环境变量覆盖的设计思路合理,但 ENABLE_EP_DP_IN_FD 的解析方式存在健壮性问题,需要修复。

self.config.namespace = os.getenv("AS_NAMESPACE", self.config.namespace)
self.config.pod_name = os.getenv("AS_POD_NAME", self.config.pod_name)
if int(os.getenv("ENABLE_EP_DP_IN_FD", "1")):
self.config.pod_name = self.config.pod_name + "_" + self.config.splitwise_role + "_" + str(self.config.dp_id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug int(os.getenv("ENABLE_EP_DP_IN_FD", "1")) 当环境变量被设置为非数字字符串(如 "true""false""enabled")时,int() 会抛出 ValueError

由于此处位于 try ... except Exception 块内,异常会被捕获并导致整个 AttentionStoreSDK 初始化失败,且错误信息会令人困惑(不会提示是环境变量格式问题)。

建议使用更健壮的解析方式:

def _str_to_bool(val: str) -> bool:
    return val.strip().lower() not in ("0", "false", "no", "off", "")

if _str_to_bool(os.getenv("ENABLE_EP_DP_IN_FD", "1")):

或者至少增加异常处理:

try:
    enable_ep_dp = int(os.getenv("ENABLE_EP_DP_IN_FD", "1"))
except ValueError:
    enable_ep_dp = 1
    logger.warning("ENABLE_EP_DP_IN_FD 环境变量值无效,使用默认值 1")
if enable_ep_dp:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants